<!DOCTYPE html>
<html>
<head>
    <title>游记问答</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
    <link rel="stylesheet" href="/css/reset.css" />
    <link rel="stylesheet" href="/css/myInfo.css" />
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css" />
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/plugins/form/jquery.form.js"></script>
    <script src="/js/plugins/eleditor/Eleditor.min.js"></script>
    <script src="/js/plugins/eleditor/webuploader.min.js"></script>
    <script src="/js/checkLogin.js"></script>
    <script src="/js/common.js"></script>
</head>

<body style="background: url('/upload/2.bmp')">
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>我的提问</span>
        </div>
        <div class="col"></div>
    </div>
</div>

<div class="container travels">
    <dl class="list" render-loop="list">
        <dd>
            <a data-url="/mine/editTravelTroubles.html?id=" render-key="list.id" render-fun="getHref">
                <h4 render-fun="getName" render-key="list.title"></h4>
            </a>
            <p style="color: #c69500">提问于 <span render-html="list.lastUpdateTime"></span>
                <span class="span-right">
                        <i class="fa fa-address-book"></i>
                    <span style="color: orange"
                          render-html="list.stateName"></span>
                     </span>
            </p>

        </dd>
    </dl>
    <hr>
</div>

<script>
    $(function () {

        var currentPage = 1;
        var travels;
        var pages;

        // 从本地session中取出缓存的对象,渲染到页面
        var user = JSON.parse(sessionStorage.getItem("user"));

        $(".question").click(function () {
            location.href = "/mine/editTravelTroubles.html"
        });
        // 发请求获取数据
        $.get(baseUrl+"/users/" + user.id + "/travelTroubles", {pageSize: 3}, function (data) {
            var index = 1;
            $(".travels").renderValues(data, {
              getHref:getHref,
              getName:function(item,value){
                    $(item).html(index++ +"."+value);
                }
            });

            travels = data.list;
            // 需要用到总页数,所以先获取
            pages = data.pages;
            console.log(pages);
        });

        $(window).scroll(function () {
            console.log(isEnd());
            if (isEnd()) {
                if (currentPage < pages) {
                    currentPage++;
                    console.log(currentPage);
                    $.get(baseUrl+"/users/" + user.id + "/travelTroubles", {
                        currentPage: currentPage,
                        pageSize: 3
                    }, function (data) {
                        $.merge(travels, data.list);
                        renderView({list: travels});
                    });
                } else {
                    $(document).dialog({
                        type: 'notice',
                        infoText: '我也是有底线的',
                        autoClose: 1500,
                        position: 'bottom'  // center: 居中; bottom: 底部
                    });
                }
            }
        })

    });

</script>
</body>
</html>
